var heatVertex1 = `
    uniform sampler2D heightMap;
    uniform float heightRatio;
    varying vec2 vUv;
    varying float hValue;
    void main() {
      vUv = uv;
      vec3 pos = position;
      hValue = texture2D(heightMap, vUv).r;
      pos.y = hValue * heightRatio;
      gl_Position = projectionMatrix * modelViewMatrix * vec4(pos,1.0);
    }
  `;

var heatFragment1 = `
    varying float hValue;
    
    // honestly stolen from https://www.shadertoy.com/view/4dsSzr
    vec3 heatmapGradient(float t) {
      return clamp((pow(t, 1.5) * 0.8 + 0.2) * vec3(smoothstep(0.0, 0.35, t) + t * 0.5, smoothstep(0.5, 1.0, t), max(1.0 - t * 1.7, t * 7.0 - 6.0)), 0.0, 1.0);
    }

    void main() {
      float v = abs(hValue - 1.);
      gl_FragColor = vec4(heatmapGradient(hValue), 1. - v * v) ;
    }
  `;

var heightMap1 = createHeightMap();
console.log(heightMap);
function createHeightMap(){
    var canvas = document.createElement("canvas");
    canvas.width = 256;
    canvas.height = 256;
    var ctx = canvas.getContext("2d");
    ctx.fillStyle = "black";
    ctx.fillRect(0, 0, 256, 256);
    for(let i = 0; i < 10; i++){
        // var x = Math.floor(Math.random() * 255);
        //   var y = Math.floor(Math.random() * 255);//453120.31, 4425204.48   452560.24, 4425379.26  ;(453038 - 452560.24)/(453120 - 452560.24)
        var x =  Math.floor((453038 - 452560)/(453485 - 452560)*255);
        var y = Math.floor((4425379 - 4425073)/(4425379 - 4424854)*255);
        var radius = 10;
        var grd = ctx.createRadialGradient(x, y, 1, x, y, radius);
        var h8 = Math.floor(Math.random() * 255);
        grd.addColorStop(0, "rgb("+ h8 + "," + h8 + "," + h8 +")");
        grd.addColorStop(1, "transparent");
        ctx.fillStyle = grd;
        ctx.fillRect(0, 0, 256, 256);
    }
    return new THREE.CanvasTexture(canvas);
}
// export default {
//     heatVertex: function(){
//         return heatVertex
//     },
//     heatFragment: function(){
//         return heatFragment
//     },
//     heightMap: function(){
//         return heightMap
//     }
// }
export function  heatVertex() {
    return heatVertex1
}
export function  heightMap() {
    return heightMap1
}
export function  heatFragment() {
    return heatFragment1
}
